package com.ruoyi.student.controller;


import com.ruoyi.classes.service.IXzkClassesService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.student.domain.XzkInfoStudent;
import com.ruoyi.student.domain.XzkStudent;
import com.ruoyi.student.service.IXzkInfoStudentService;
import com.ruoyi.student.service.IXzkStudentService;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.util.*;

/**
 * 学生信息Controller
 *
 * @author ruoyi
 * @date 2021-04-02
 */
@Controller
@RequestMapping("/student/dropstudent")
public class XzkDropStudentController extends BaseController
{
    private String prefix = "student/student";

    @Autowired
    private IXzkStudentService xzkStudentService;

    @Autowired
    private IXzkInfoStudentService xzkInfoStudentService;

    @Autowired
    private IXzkClassesService xzkClassesService;

    @RequiresPermissions("student:dropstudent:view")
    @GetMapping()
    public String student()
    {
        return prefix + "/dropstudent";
    }





    private void getColorType( XzkStudent student){
        if (student.getSuperviseclasslasttime()!=null){
            Date date=new Date();
            int days = (int) ((date.getTime() - student.getSuperviseclasslasttime().getTime()) / (1000*3600*24));
            if (days<=5){
                student.setColorType(1);
            }else if(days<=8){
                student.setColorType(2);
            }else {
                student.setColorType(3);
            }
        }else {
            student.setColorType(1);
        }
    }


    /**
     * 查询退休学学员信息
     * */
    @RequiresPermissions("student:student:list")
    @PostMapping("/list2")
    @ResponseBody
    public TableDataInfo list2(XzkStudent xzkStudent, HttpSession session)
    {
        String userName = (String)session.getAttribute("userName");
        startPage();
        List<XzkStudent> list = xzkStudentService.selectXzkStudentList2(xzkStudent,userName);
        for (XzkStudent student : list) {
            getColorType(student);
        }
        return getDataTable(list);
    }


}
